package com.lbsq.user.action;


import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.lbsq.user.pojo.User;
import com.lbsq.user.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


public class UserAction
    extends ActionSupport
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 4500839845124745968L;

	private UserService userService;

    //private User user;
   
    public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	private String password;
    
    private String userName;

    private List<User> userList;

    public String sendRedirectLoginPage()
        throws Exception
    {
        return SUCCESS;
    }

	public String login() throws Exception {
		User tempUser = new User();
		tempUser.setUserName(getUserName());
		tempUser.setPassword(getPassword());
		
		User u = userService.login(tempUser);
		//user = u;
		if (u != null && u.getId()==null) {
			return ERROR;
		} else {
//			ActionContext.getContext().getValueStack().set("Hello", "Hello");
//			HttpServletRequest req = ServletActionContext.getRequest();
//			req.setAttribute("userName", "xiejiarong2");
			return SUCCESS;
		}
		
	}

    public String userList()
        throws Exception
    {
        userList = userService.selectUserList();
        return SUCCESS;
    }
    
    
	public String isUserExist() throws Exception {
		User u = userService.getUserByUserName(getUserName());
		this.userName = u == null ? "" : u.getUserName();
		return SUCCESS;
	}

    public void setUserService(UserService userService)
    {
        this.userService = userService;
    }

//    public User getUser()
//    {
//        return user;
//    }

//    public void setUser(User user)
//    {
//        this.user = user;
//    }

    public List<User> getUserList()
    {
        return userList;
    }

    public void setUserList(List<User> userList)
    {
        this.userList = userList;
    }

//	public Object getModel() {
//		return user;
//	}

}
